using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using MobileClient.UIProcessService;

namespace MobileClient
{
	public class ImageButton: Control
	{
		public enum ButtonType
		{
			Button, 
			ToggleButton
		}

		private ButtonType mode = ButtonType.Button;
		private bool pressed = false;
		private Image imageButtonUp = null;
		private Image imageButtonDown = null;

		public ImageButton()
		{
			base.BackColor = Color.White;
		}

		protected override void OnPaint(PaintEventArgs pea)
		{
			base.OnPaint(pea);

			pea.Graphics.FillRectangle(new SolidBrush(Color.White), 0,0,this.Width,this.Height);

			//Create Image
			if (Pressed)
			{
				if (imageButtonDown != null)
				{
					pea.Graphics.DrawImage(imageButtonDown, 0,0);
				}
			}
			else 
			{
				if (imageButtonUp != null)
				{
					pea.Graphics.DrawImage(imageButtonUp, 0,0);
				}
			}
		}


		protected override void OnMouseDown(MouseEventArgs me)
		{
			if (mode == ButtonType.ToggleButton) 
			{
				Pressed = !Pressed;
			}
			if (mode == ButtonType.Button)
			{
				Pressed = true;
			}
		}

		protected override void OnMouseUp(MouseEventArgs me)
		{
			if (mode == ButtonType.Button) 
			{
				Pressed = false;
			}
		}
		

		public bool Pressed
		{
			get
			{
				return pressed;
			}
			set
			{
				pressed = value;
				this.Refresh();
			}
		}

		public Image ImageButtonUp
		{
			get 
			{
				return imageButtonUp;
			}
			set
			{
				imageButtonUp = value;
			}
		}

		public Image ImageButtonDown
		{
			get 
			{
				return imageButtonDown;
			}
			set
			{
				imageButtonDown = value;
			}
		}

		public ButtonType Type
		{
			get
			{
				return mode;
			}
			set
			{
				mode = value;
			}
		}
	}
}
